// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/common/time/timer.h>

#include <pollux/common/testutil/scoped_test_time.h>

namespace kumo::pollux {
    using namespace std::chrono;
    using common::testutil::ScopedTestTime;

#ifndef NDEBUG

    uint64_t getCurrentTimeSec() {
        return ScopedTestTime::getCurrentTestTimeSec().value_or(
            duration_cast<seconds>(system_clock::now().time_since_epoch()).count());
    }

    uint64_t getCurrentTimeMs() {
        return ScopedTestTime::getCurrentTestTimeMs().value_or(
            duration_cast<milliseconds>(system_clock::now().time_since_epoch())
            .count());
    }

    uint64_t getCurrentTimeMicro() {
        return ScopedTestTime::getCurrentTestTimeMicro().value_or(
            duration_cast<microseconds>(system_clock::now().time_since_epoch())
            .count());
    }

    uint64_t getCurrentTimeNano() {
        return ScopedTestTime::getCurrentTestTimeNano().value_or(
            duration_cast<nanoseconds>(system_clock::now().time_since_epoch())
            .count());
    }
#else

uint64_t getCurrentTimeSec() {
  return duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
}

uint64_t getCurrentTimeMs() {
  return duration_cast<milliseconds>(system_clock::now().time_since_epoch())
      .count();
}

uint64_t getCurrentTimeMicro() {
  return duration_cast<microseconds>(system_clock::now().time_since_epoch())
      .count();
}

uint64_t getCurrentTimeNano() {
  return duration_cast<nanoseconds>(system_clock::now().time_since_epoch())
      .count();
}
#endif
} // namespace kumo::pollux
